package com.example.api.controller;

import com.example.api.model.constants.LogisticsConstants;
import com.example.api.model.support.RespBean;
import com.example.api.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Api(tags = "文件管理")
@RestController
@RequestMapping("/api/file")
public class FileController {

    @Resource
    private FileService fileService;

    @ApiOperation("上传文件")
    @PostMapping("/upload")
    public Integer upload(MultipartFile file, String module) {
        try {
            return fileService.upload(module, file, LogisticsConstants.RESOURCE_SERVICE_TYPE_1, LogisticsConstants.RESOURCE_OBJECT_TYPE_2);
        } catch (Exception e) {
            throw new RuntimeException("上传异常");
        }
    }

    @ApiOperation("下载文件")
    @PostMapping("/download")
    public RespBean download() {
        try {
            return fileService.download();
        } catch (Exception e) {
            throw new RuntimeException("下载异常");
        }
    }

}
